package ord2.core;

/**
 * This interface indentifies a factory of objects of a given type. Each instance
 * has a identifier that is used to retrieve a instance.
 *
 * @author José Ivan
 * @author Edviges
 * 
 */
public interface Factory<K, V> {
    
    /**
     * Attaches a instance to this factory with a key that will be used to retrieve
     * this instance.
     * @param key Key to attach a instance
     * @param value Object that will be attached
     * @return false on failure or true otherwise
     */
    boolean attachInstance(K key, V value);
    
    /**
     * Gets a instance that was attached to this factory or null if none instance
     * was attached with given key
     * @param key Key used to retrieve the instance.
     * @return Instance attached with given key or null
     */
    V getAttachedInstance(K key);
    
    /**
     * Retrieves all attached instances in this factory.
     * @return Array containing all instances of this factory.
     */
    V[] getAllAttachedInstances();
    
    /**
     * Retrieves all keys that are being used by this factory
     * @return Array containg all keys
     */
    K[] getAllKeys();
}
